
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Pagination {
    //put your code here
    public function display($total, $page) {
      
        $pages = $total/PER_PAGE;
        $html = "<a href='index.php?page=$page'>$page</a>";
        
        $count = 1;
        for ($i = 1; $i < PER_PAGE; $i++) {
            if ($page + $i <= $pages) {
                $li = $page + $i;
                $html .= "<a href='index.php?page=$li'> $li</a>";
                $count++;
            }
            if ($count >= PER_PAGE) break;
            if ($page - $i > 0) {
                $li = $page - $i;
                $html = "<a href='index.php?page=$li'>$li </a>$html";
                $count++;
            }            
            if ($count >= PER_PAGE) break;
        }
          //First-Prev-Next-Last
        if ($page - 1 > 0) {
            $li = $page - 1;
            $html = "<a href='index.php?page=$li'> Prev </a>".$html;
        }
        if ($page + 1 <= $pages) {
            $li = $page + 1;
            $html .= "<a href='index.php?page=$li'> Next </a>";
        }
        if ($page != 1) {
            $html = "<a href='index.php?page=1'> First </a>".$html;
        }
        if ($page != $pages) {
            $html = $html."<a href='index.php?page=$pages'> Last </a>";
        }
        return $html;
    }
}
        ?>